package com.atguigu.exam;

/**
 * 封装一个新闻类News，包含新闻标题，新闻作者，新闻内容，新闻类型三个属性，
 * 提供必要的访问器和修改器方法，重写toString方法，要求打印对象时输出格式
 * 为“标题；类型；作者”，要求只要新闻标题相同就判断为同一条新闻。在测试类
 * 中创建一个只能容纳该类对象的ArrayList集合，添加三条新闻。遍历集合，打
 * 印新闻标题，将新闻标题截取字符串到10个汉字的长度。
 *
 * @author xbd
 * @create 2021-05-29 17:47
 */
public class News<T> {
    private String title;
    private String author;
    private String body;
    private T type;

    public News() {
    }

    public News(String title, String author, String body) {
        this.title = title;
        this.author = author;
        this.body = body;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public T getType() {
        return type;
    }

    public void setType(T type) {
        this.type = type;
    }

    @Override
    public String toString() {
        return "标题：" + title + ";\n类型：" + type + ";\n作者：" + author;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        News<?> news = (News<?>) o;

        return title.equals(news.title);
    }

}

class Society{

}

class Entertainment{

}
